Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • esttab produces redundant table openings &\multicolumns{}, when looping and appending regression results, that can not be suppressed

    Dear Ben Jann,

    I am very much thankful for all the scripts and packages that you have written so far and all the possibilities that result from these powerful tools!! Usually I have found a workaround or solution for possible problems and applications, however this time I am running out of ideas.

    I hope you (or Andrew Musau or Nils Enevoldsen f.e.) will find some time to give me a proper hint to solve the following problem. The following code (see first code chunk) produces redundant table beginnings, when looping and appending regression results with esttab. (&\multicolumn{})
    Almost the same code (see second code chunk) creates summary statistics over a couple of variables for different birth cohorts separately, which works absolutely fine for the tabstat command.

    My guess is, that it is because the tabstat results end up in one matrix per covariate, whereas the weighted ttests calculated with bivariate regression results produce one matrix for each category of every variable of interest.This seemingly results in redundant table openings:
    &\multicolumn{1}{c}{pov\_ynhhinc\_new\_p50}&\multi column{1}{c}{pov\_ynhhinc\_new\_p50}\\
    where I would expect a simple \addlinespace. This crashes the whole routine and table. None of the options to suppress these issues or ideas in forums could solve the problem so far.
    Click image for larger version

Name:	Screen Shot 2020-06-20 at 05.03.40.png
Views:	1
Size:	138.9 KB
ID:	1559786


    Fixed by hand, the outcome of desire would look like this:
    Click image for larger version

Name:	Screen Shot 2020-06-20 at 05.04.05.png
Views:	1
Size:	115.0 KB
ID:	1559785


    The problematic code:

    Code:
        /* Zeit (Makro) – T-Test (Differenz Kohorte 1950-59 mit 1970-80)             */
        foreach cut in p50 mean {
            foreach var of global time {
              foreach num of numlist 0 {
            
                * Extract first value label as identifier (refcat)
                levelsof `var', local(levels)
                local lbe : value label `var'
                
                foreach l of local levels {
                    local f`l' : label `lbe' `l'
                }
                di "`f0'"
                
                * Extract variable label for (refcat)
                qui fre `var'
                local l_`var' = "`r(label)'"
                *local l_`var' = "`e(labels)'"
                disp in red "`l_`var''"
                
                * Extract value label for title
                levelsof cohort, local(levels)
                local lba : value label cohort
                
                foreach l of local levels {
                    local a`l' : label `lba' `l'
                }
                di "`a`coh''"
                local diff "{$\Delta$}: (1970er) -- (1950er)"
            
            
            * Einheimische:
            reg pov_ynhhinc_new_`cut' i.cohort [aweight=phrfe] ///
            if mig==0 & `var'==`num' & cohort!=1
            est store a_pom_`cut'_`var'_`num'
            
            * Zugewanderte:
            reg pov_ynhhinc_new_`cut' i.cohort [aweight=phrfe] ///
            if mig==1 & `var'==`num' & cohort!=1
            est store a_pmm_`cut'_`var'_`num'
            
            
            * Header : a
            esttab a_pom_`cut'_`var'_`num' a_pmm_`cut'_`var'_`num' ///
            using "${LOG_PATH}/00-table-pov-bycoh-`cut'-a3.tex", append ///
             mgroups("\multicolumn{2}{c}{`diff'}") ///
                mtitles("\textbf{\emph{PoM}}" "\textbf{\emph{PmM}}") ///
                     prehead("\textbf{Zeiträume}") ///
                        refcat("2.cohort" "\emph{`l_`var''}", nolabel) ///
            collabels(none) alignment(S) b(a1) star(* 0.05 ** 0.01 *** 0.001)  ///
            wide booktabs fragment gaps compress transform(@*100) ///
            nonote noobs nonumber nolines not drop(0.cohort* _cons*)
            
            * Header : b
            esttab a_pom_`cut'_`var'_`num' a_pmm_`cut'_`var'_`num' ///
            using "${LOG_PATH}/00-table-pov-bycoh-`cut'-b3.tex", append ///
             mgroups("\multicolumn{2}{c}{`diff'}") ///
                mtitles("\textbf{\emph{PoM}}" "\textbf{\emph{PmM}}") ///
                     prehead("\textbf{Zeiträume}") ///
                        refcat("2.cohort" "\emph{`l_`var''}", nolabel) ///
            collabels(none) alignment(S) b(a1) star(* 0.05 ** 0.01 *** 0.001)  ///
            wide booktabs fragment gaps compress transform(@*100) ///
            nonote noobs nonumber nolines not drop(0.cohort* _cons*)
                }
            }
        }
        
        * - - - - - - - - - - - - - - - - - *
        
        foreach cut in p50 mean {
            foreach var of global time {
              foreach num of numlist 1/5 {
            
                * Extract first value label as identifier (refcat)
                levelsof `var', local(levels)
                local lbe : value label `var'
                
                foreach l of local levels {
                    local f`l' : label `lbe' `l'
                }
                di "`f0'"
                
                * Extract variable label for (refcat)
                qui fre `var' if `var'== `num'
                local l_`var' = "`r(label)'"
                *local l_`var' = "`e(labels)'"
                disp in red "`l_`var''"
                
                * Extract value label for title
                levelsof cohort, local(levels)
                local lba : value label cohort
                
                foreach l of local levels {
                    local a`l' : label `lba' `l'
                }
                di "`a`coh''"
                local diff "{$\Delta$}: (1970er) -- (1950er)"
            
            
            * Einheimische:
            reg pov_ynhhinc_new_`cut' i.cohort [aweight=phrfe] ///
            if mig==0 & `var'==`num' & cohort!=1
            est store a_pom_`cut'_`var'_`num'
            
            * Zugewanderte:
            reg pov_ynhhinc_new_`cut' i.cohort [aweight=phrfe] ///
            if mig==1 & `var'==`num' & cohort!=1
            est store a_pmm_`cut'_`var'_`num'
                        
                        
            * Header : a
            esttab a_pom_`cut'_`var'_`num' a_pmm_`cut'_`var'_`num' ///
            using "${LOG_PATH}/00-table-pov-bycoh-`cut'-a3.tex", append ///
            collabels(none) alignment(S) b(a1) star(* 0.05 ** 0.01 *** 0.001)  ///
            wide booktabs fragment compress transform(@*100) ///
            nonote noobs nonumber nolines not keep(2.cohort*)
            
            * Header : b
            esttab a_pom_`cut'_`var'_`num' a_pmm_`cut'_`var'_`num' ///
            using "${LOG_PATH}/00-table-pov-bycoh-`cut'-b3.tex", append ///
            collabels(none) alignment(S) b(a1) star(* 0.05 ** 0.01 *** 0.001)  ///
            wide booktabs fragment compress transform(@*100) ///
            nonote noobs nonumber nolines not keep(2.cohort*) 
            
                }
            }
        }




    My source code:

    Code:
    /*    D E S K R I P T I O N: Gesamt (1) – über alle Zeitpunkte -vs- Alterskohorten (2)
                                          – über alle Zeitpunkte -vs- Geburtskohorten (3) */
        global time      syear_cat 
        global microI     age_cat
        global micro     gender edu_cat emplstat egp_last /* isei */ subj_health
        global mesoI      famstat
        global meso      kidshh_cat housing 
        global macroI     eastwest
        global macro     loc1989 fed_state muncip econ_sector
            
        * ––––––––––––––––– *
        *  (1) G E S A M T  *
        * ––––––––––––––––– *
                   
        // (1) Gesamt: Alle in Deutschland lebenden Personen im erwerbsfähigen Alter
        foreach let in a b c {
        cap erase "${LOG_PATH}/00-table-pov-p50-`let'.tex"
        cap erase "${LOG_PATH}/00-table-pov-mean-`let'.tex"
        }
        
        eststo clear
        estimates clear
        
        
        /* Zeit (Makro) */
        foreach cut in p50 mean {
            foreach var of global time {
        estpost tabstat pov_ynhhinc_new_`cut' [aweight=phrfe], ///
        by(`var') statistics(mean) columns(statistics) nototal
        est store a_ges_`cut'_`var'
        estadd matrix pc = e(mean)*100
        
            * Extract first value label as identifier (refcat)
            levelsof `var', local(levels)
            local lbe : value label `var'
            
            foreach l of local levels {
                local f`l' : label `lbe' `l'
            }
            di "`f0'"
            
            * Extract variable label for (refcat)
            qui fre `var'
            local l_`var' = "`r(label)'"
            *local l_`var' = "`e(labels)'"
            disp in red "`l_`var''"
            
            * Header : a
            esttab a_ges_`cut'_`var' ///
            using "${LOG_PATH}/00-table-pov-`cut'-a.tex", append ///
             mgroups(" ") ///
             mtitles("{\normalsize\textbf{$\diameter$}}") ///
                prehead("\textbf{Zeiträume}") ///
                    refcat("`f0'" "\emph{`l_`var''}", nolabel) ///
                        collabels(none) cells("pc(fmt(1))") alignment(S)  ///
            label wide booktabs fragment nonote noobs nonumber gaps compress nolines
            
            * Header : b
            esttab a_ges_`cut'_`var' ///
            using "${LOG_PATH}/00-table-pov-`cut'-b.tex", append ///
             mgroups(" ") ///
             mtitles("{\normalsize\textbf{$\diameter$}}") ///
                prehead("\textbf{Zeiträume}") ///
                    refcat("`f0'" "\emph{`l_`var''}", nolabel) ///
                        collabels(none) cells("pc(fmt(1))") alignment(S)  ///
            label wide booktabs fragment nonote noobs nonumber gaps compress nolines
                }
            }
    
        * - - - - - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - - - - - - *
        
        /* Individualmerkmale (MikroI) */
        foreach cut in p50 mean {
            foreach var of global microI {
        estpost tabstat pov_ynhhinc_new_`cut' [aweight=phrfe], ///
        by(`var') statistics(mean) columns(statistics) nototal
        est store a_ges_`cut'_`var'
        estadd matrix pc = e(mean)*100
        
            * Extract first value label as identifier (refcat)
            levelsof `var', local(levels)
            local lbe : value label `var'
            
            foreach l of local levels {
                local f`l' : label `lbe' `l'
            }
            di "`f0'"
            
            * Extract variable label for (refcat)
            qui fre `var'
            local l_`var' = "`r(label)'"
            *local l_`var' = "`e(labels)'"
            disp in red "`l_`var''"
            
            esttab a_ges_`cut'_`var' ///
            using "${LOG_PATH}/00-table-pov-`cut'-a.tex", append ///
                prehead(\\ \bottomrule \addlinespace "\textbf{Individualmerkmale}") ///
                    refcat("`f0'" "\emph{`l_`var''}", nolabel) ///
                        collabels(none) cells("pc(fmt(1))") alignment(S)  ///
            label wide booktabs fragment nonote noobs nonumber gaps compress nolines
                }
            }    
        
        /* Individualmerkmale (Mikro) */
        foreach cut in p50 mean {
            foreach var of global micro {
        estpost tabstat pov_ynhhinc_new_`cut' [aweight=phrfe], ///
        by(`var') statistics(mean) columns(statistics) nototal
        est store a_ges_`cut'_`var'
        estadd matrix pc = e(mean)*100
        
            * Extract first value label as identifier (refcat)
            levelsof `var', local(levels)
            local lbe : value label `var'
            
            foreach l of local levels {
                local f`l' : label `lbe' `l'
            }
            di "`f0'"
            
            * Extract variable label for (refcat)
            qui fre `var'
            local l_`var' = "`r(label)'"
            *local l_`var' = "`e(labels)'"
            disp in red "`l_`var''"
            
            esttab a_ges_`cut'_`var' ///
            using "${LOG_PATH}/00-table-pov-`cut'-a.tex", append ///
                refcat("`f0'" "\emph{`l_`var''}", nolabel) ///
                    collabels(none) cells("pc(fmt(1))") alignment(S)  ///
            label wide booktabs fragment nonote noobs nonumber gaps compress nolines
                }
            eststo clear
            estimates clear
            }    
        
        * - - - - - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - - - - - - *
    
    
    *------------------------------------------------------------------------------*
    *------------------------------------------------------------------------------*
    
    
        * ––––––––––––––––––––––––––––––----- *
        *  (3) G E B U R T S K O H O R T E N  *
        * –––––––––––––––––––––––––––––––---- *
        global time      syear_cat 
        global microI     age_cat
        global micro     gender edu_cat emplstat egp_last isei subj_health
        global mesoI      famstat
        global meso      kidshh_cat housing 
        global macroI     eastwest
        global macro     loc1989 fed_state muncip econ_sector
    
                     
        // (2) Spezifisch: Einheimische -vs- Zugewanderte nach Geburtskohorten
        foreach let in a b c {
            foreach coh of numlist 0/3 {
        cap erase "${LOG_PATH}/00-table-pov-bycoh-p50-`let'`coh'.tex"
        cap erase "${LOG_PATH}/00-table-pov-bycoh-p50-`let'`coh'.tex"
        cap erase "${LOG_PATH}/00-table-pov-bycoh-mean-`let'`coh'.tex"
        cap erase "${LOG_PATH}/00-table-pov-bycoh-mean-`let'`coh'.tex"
        eststo clear
            }
        }
        
        /* Zeit (Makro) – 1. Spalte Tabelle (Kohorte mit Value labels) */
        foreach coh of numlist 0 {
        foreach cut in p50 mean {
            foreach var of global time {
                
            
            * Einheimische:
            estpost tabstat pov_ynhhinc_new_`cut' [aweight=phrfe] ///
            if mig==0 & cohort==`coh', ///
            by(`var') statistics(mean) columns(statistics) nototal
            est store a_pom_`cut'_`var'_`coh'
            estadd matrix pc = e(mean)*100
    
            
            * Zugewanderte (Gesamt):
            estpost tabstat pov_ynhhinc_new_`cut' [aweight=phrfe] ///
            if mig==1 & cohort==`coh', ///
            by(`var') statistics(mean) columns(statistics) nototal
            est store a_pmm_`cut'_`var'_`coh'
            estadd matrix pc = e(mean)*100
            
        
                * Extract first value label as identifier (refcat)
                levelsof `var', local(levels)
                local lbe : value label `var'
                
                foreach l of local levels {
                    local f`l' : label `lbe' `l'
                }
                di "`f0'"
                
                * Extract variable label for (refcat)
                qui fre `var'
                local l_`var' = "`r(label)'"
                *local l_`var' = "`e(labels)'"
                disp in red "`l_`var''"
                
                * Extract value label for title
                levelsof cohort, local(levels)
                local lba : value label cohort
                
                foreach l of local levels {
                    local a`l' : label `lba' `l'
                }
                di "`a`coh''"
            
            * Header : a
            esttab a_pom_`cut'_`var'_`coh' a_pmm_`cut'_`var'_`coh' ///
            using "${LOG_PATH}/00-table-pov-bycoh-`cut'-a`coh'.tex", append ///
             mgroups("\multicolumn{2}{c}{`a`coh''}") ///
                mtitles("\textbf{\emph{PoM}}" "\textbf{\emph{PmM}}") ///
                     prehead("\textbf{Zeiträume}") ///
                      refcat("`f0'" "\emph{`l_`var''}", nolabel) ///
                        collabels(none) cells("pc(fmt(1))") alignment(S)  ///
            label wide booktabs fragment nonote noobs nonumber gaps compress nolines
            
            * Header : b
            esttab a_pom_`cut'_`var'_`coh' a_pmm_`cut'_`var'_`coh' ///
            using "${LOG_PATH}/00-table-pov-bycoh-`cut'-b`coh'.tex", append ///
             mgroups("\multicolumn{2}{c}{`a`coh''}") ///
                mtitles("\textbf{\emph{PoM}}" "\textbf{\emph{PmM}}") ///
                     prehead("\textbf{Zeiträume}") ///
                      refcat("`f0'" "\emph{`l_`var''}", nolabel) ///
                        collabels(none) cells("pc(fmt(1))") alignment(S)  ///
            label wide booktabs fragment nonote noobs nonumber gaps compress nolines
                }
            }
        }
        
        * - - - - - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - - - - - - *
    
        /* Zeit (Makro) – X. Spalte Tabelle (Kohorte OHNE Value labels) */
        foreach coh of numlist 1/2 {
        foreach cut in p50 mean {
            foreach var of global time {
                
            
            * Einheimische:
            estpost tabstat pov_ynhhinc_new_`cut' [aweight=phrfe] ///
            if mig==0 & cohort==`coh', ///
            by(`var') statistics(mean) columns(statistics) nototal
            est store a_pom_`cut'_`var'_`coh'
            estadd matrix pc = e(mean)*100
            
            * Zugewanderte (Gesamt):
            estpost tabstat pov_ynhhinc_new_`cut' [aweight=phrfe] ///
            if mig==1 & cohort==`coh', ///
            by(`var') statistics(mean) columns(statistics) nototal
            est store a_pmm_`cut'_`var'_`coh'
            estadd matrix pc = e(mean)*100
    
        
                * Extract first value label as identifier (refcat)
                levelsof `var', local(levels)
                local lbe : value label `var'
                
                foreach l of local levels {
                    local f`l' : label `lbe' `l'
                }
                di "`f0'"
                
                * Extract variable label for (refcat)
                qui fre `var'
                local l_`var' = "`r(label)'"
                *local l_`var' = "`e(labels)'"
                disp in red "`l_`var''"
                
                * Extract value label for title
                levelsof cohort, local(levels)
                local lba : value label cohort
                
                foreach l of local levels {
                    local a`l' : label `lba' `l'
                }
                di "`a`coh''"
            
            * Header : a
            esttab a_pom_`cut'_`var'_`coh' a_pmm_`cut'_`var'_`coh' ///
            using "${LOG_PATH}/00-table-pov-bycoh-`cut'-a`coh'.tex", append ///
             mgroups("\multicolumn{2}{c}{`a`coh''}") ///
                mtitles("\textbf{\emph{PoM}}" "\textbf{\emph{PmM}}") ///
                     prehead("\textbf{Zeiträume}") ///
                      refcat("`f0'" "\emph{`l_`var''}", nolabel) ///
                        collabels(none) cells("pc(fmt(1))") alignment(S)  ///
            wide booktabs fragment nonote noobs nonumber gaps compress nolines
            
            * Header : b
            esttab a_pom_`cut'_`var'_`coh' a_pmm_`cut'_`var'_`coh' ///
            using "${LOG_PATH}/00-table-pov-bycoh-`cut'-b`coh'.tex", append ///
             mgroups("\multicolumn{2}{c}{`a`coh''}") ///
                mtitles("\textbf{\emph{PoM}}" "\textbf{\emph{PmM}}") ///
                     prehead("\textbf{Zeiträume}") ///
                      refcat("`f0'" "\emph{`l_`var''}", nolabel) ///
                        collabels(none) cells("pc(fmt(1))") alignment(S)  ///
            wide booktabs fragment nonote noobs nonumber gaps compress nolines
                }
            }
        }
        
        * - - - - - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - - - - - - *
        
        
        
        * - - - - - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - - - - - - *
        * - - - - - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - - - - - - *
    
        // I N D I V I D U A L (Mikro) : nach Geburtskohorten
        
        * - - - - - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - - - - - - *
        * - - - - - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - - - - - - *
        
        /* Individualmerkmale (MikroI) – 1. Spalte Tabelle (Kohorte mit Value labels) */
        foreach coh of numlist 0 {
        foreach cut in p50 mean {
            foreach var of global microI {
                
            
            * Einheimische:
            estpost tabstat pov_ynhhinc_new_`cut' [aweight=phrfe] ///
            if mig==0 & cohort==`coh', ///
            by(`var') statistics(mean) columns(statistics) nototal
            est store a_pom_`cut'_`var'_`coh'
            estadd matrix pc = e(mean)*100
            
            * Zugewanderte (Gesamt):
            estpost tabstat pov_ynhhinc_new_`cut' [aweight=phrfe] ///
            if mig==1 & cohort==`coh', ///
            by(`var') statistics(mean) columns(statistics) nototal
            est store a_pmm_`cut'_`var'_`coh'
            estadd matrix pc = e(mean)*100
    
        
                * Extract first value label as identifier (refcat)
                levelsof `var', local(levels)
                local lbe : value label `var'
                
                foreach l of local levels {
                    local f`l' : label `lbe' `l'
                }
                di "`f0'"
                
                * Extract variable label for (refcat)
                qui fre `var'
                local l_`var' = "`r(label)'"
                *local l_`var' = "`e(labels)'"
                disp in red "`l_`var''"
                
                * Extract value label for title
                levelsof cohort, local(levels)
                local lba : value label cohort
                
                foreach l of local levels {
                    local a`l' : label `lba' `l'
                }
                di "`a`coh''"
            
            
            esttab a_pom_`cut'_`var'_`coh' a_pmm_`cut'_`var'_`coh' ///
            using "${LOG_PATH}/00-table-pov-bycoh-`cut'-a`coh'.tex", append ///
                prehead(\\ \bottomrule \addlinespace "\textbf{Individualmerkmale}") ///
                    refcat("`f0'" "\emph{`l_`var''}", nolabel) ///
                        collabels(none) cells("pc(fmt(1))") alignment(S)  ///
            label wide booktabs fragment nonote noobs nonumber gaps compress nolines
                }
            }
        }
        
        /* Individualmerkmale (Mikro) – 1. Spalte Tabelle (Kohorte mit Value labels) */
        foreach coh of numlist 0 {
        foreach cut in p50 mean {
            foreach var of global micro {
                
            
            * Einheimische:
            estpost tabstat pov_ynhhinc_new_`cut' [aweight=phrfe] ///
            if mig==0 & cohort==`coh', ///
            by(`var') statistics(mean) columns(statistics) nototal
            est store a_pom_`cut'_`var'_`coh'
            estadd matrix pc = e(mean)*100
            
            * Zugewanderte (Gesamt):
            estpost tabstat pov_ynhhinc_new_`cut' [aweight=phrfe] ///
            if mig==1 & cohort==`coh', ///
            by(`var') statistics(mean) columns(statistics) nototal
            est store a_pmm_`cut'_`var'_`coh'
            estadd matrix pc = e(mean)*100
    
        
                * Extract first value label as identifier (refcat)
                levelsof `var', local(levels)
                local lbe : value label `var'
                
                foreach l of local levels {
                    local f`l' : label `lbe' `l'
                }
                di "`f0'"
                
                * Extract variable label for (refcat)
                qui fre `var'
                local l_`var' = "`r(label)'"
                *local l_`var' = "`e(labels)'"
                disp in red "`l_`var''"
                
                * Extract value label for title
                levelsof cohort, local(levels)
                local lba : value label cohort
                
                foreach l of local levels {
                    local a`l' : label `lba' `l'
                }
                di "`a`coh''"
            
            
            esttab a_pom_`cut'_`var'_`coh' a_pmm_`cut'_`var'_`coh' ///
            using "${LOG_PATH}/00-table-pov-bycoh-`cut'-a`coh'.tex", append ///
                      refcat("`f0'" "\emph{`l_`var''}", nolabel) ///
                        collabels(none) cells("pc(fmt(1))") alignment(S)  ///
            label wide booktabs fragment nonote noobs nonumber gaps compress nolines
                }
            }
        }
        
        * - - - - - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - - - - - - *
    
        /* Individualmerkmale (MikroI) – X. Spalte Tabelle (Kohorte OHNE Value labels) */
        foreach coh of numlist 1/2 {
        foreach cut in p50 mean {
            foreach var of global microI {
                
            
            * Einheimische:
            estpost tabstat pov_ynhhinc_new_`cut' [aweight=phrfe] ///
            if mig==0 & cohort==`coh', ///
            by(`var') statistics(mean) columns(statistics) nototal
            est store a_pom_`cut'_`var'_`coh'
            estadd matrix pc = e(mean)*100
            
            * Zugewanderte (Gesamt):
            estpost tabstat pov_ynhhinc_new_`cut' [aweight=phrfe] ///
            if mig==1 & cohort==`coh', ///
            by(`var') statistics(mean) columns(statistics) nototal
            est store a_pmm_`cut'_`var'_`coh'
            estadd matrix pc = e(mean)*100
    
        
                * Extract first value label as identifier (refcat)
                levelsof `var', local(levels)
                local lbe : value label `var'
                
                foreach l of local levels {
                    local f`l' : label `lbe' `l'
                }
                di "`f0'"
                
                * Extract variable label for (refcat)
                qui fre `var'
                local l_`var' = "`r(label)'"
                *local l_`var' = "`e(labels)'"
                disp in red "`l_`var''"
                
                * Extract value label for title
                levelsof cohort, local(levels)
                local lba : value label cohort
                
                foreach l of local levels {
                    local a`l' : label `lba' `l'
                }
                di "`a`coh''"
            
            
            esttab a_pom_`cut'_`var'_`coh' a_pmm_`cut'_`var'_`coh' ///
            using "${LOG_PATH}/00-table-pov-bycoh-`cut'-a`coh'.tex", append ///
                prehead(\\ \bottomrule \addlinespace "\textbf{Individualmerkmale}") ///
                    refcat("`f0'" "\emph{`l_`var''}", nolabel) ///
                        collabels(none) cells("pc(fmt(1))") alignment(S)  ///
            label wide booktabs fragment nonote noobs nonumber gaps compress nolines
                }
            }
        }
        
        /* Individualmerkmale (Mikro) – X. Spalte Tabelle (Kohorte OHNE Value labels) */
        foreach coh of numlist 1/2 {
        foreach cut in p50 mean {
            foreach var of global micro {
                
            
            * Einheimische:
            estpost tabstat pov_ynhhinc_new_`cut' [aweight=phrfe] ///
            if mig==0 & cohort==`coh', ///
            by(`var') statistics(mean) columns(statistics) nototal
            est store a_pom_`cut'_`var'_`coh'
            estadd matrix pc = e(mean)*100
            
            * Zugewanderte (Gesamt):
            estpost tabstat pov_ynhhinc_new_`cut' [aweight=phrfe] ///
            if mig==1 & cohort==`coh', ///
            by(`var') statistics(mean) columns(statistics) nototal
            est store a_pmm_`cut'_`var'_`coh'
            estadd matrix pc = e(mean)*100
    
        
                * Extract first value label as identifier (refcat)
                levelsof `var', local(levels)
                local lbe : value label `var'
                
                foreach l of local levels {
                    local f`l' : label `lbe' `l'
                }
                di "`f0'"
                
                * Extract variable label for (refcat)
                qui fre `var'
                local l_`var' = "`r(label)'"
                *local l_`var' = "`e(labels)'"
                disp in red "`l_`var''"
                
                * Extract value label for title
                levelsof cohort, local(levels)
                local lba : value label cohort
                
                foreach l of local levels {
                    local a`l' : label `lba' `l'
                }
                di "`a`coh''"
            
            
            esttab a_pom_`cut'_`var'_`coh' a_pmm_`cut'_`var'_`coh' ///
            using "${LOG_PATH}/00-table-pov-bycoh-`cut'-a`coh'.tex", append ///
                      refcat("`f0'" "\emph{`l_`var''}", nolabel) ///
                        collabels(none) cells("pc(fmt(1))") alignment(S)  ///
            wide booktabs fragment nonote noobs nonumber gaps compress nolines
                }
            }
        }
    Attached Files

  • #2
    Dear Ben Jann,

    I am very sorry for the inconvenience, I finally found a very simple solution you have implemented:
    Code:
    nomtitles
    I overlooked this reading the very complex and helpful documentation and trying to code a workaround.
    May I use this situation at least to thank you Ben Jann and all the other great advisors (Nils Enevoldsen, Andrew Musau, Richard Williams , Nick Cox, Clyde Schechter, @Maarten Buis and many more) for your seemingly infinite support!! Due to your commitment it is not necessary to post here very often and to make many analyses possible in a very convenient way.

    All the best to you guys,
    Sascha

    Comment


    • #3
      Hi Sascha-Christopher Geschke ,

      I just bumped into a similar issue than you. I'm also producing a table using information stored after -tabstat-.

      In my case, I added \multicolumn in -prehead()- this way:

      Code:
      esttab      ///
          using "`directory'/tables/table1-becker-pooled-clustered.tex"     ///
          ,         ///
          cells("mean(fmt(1)) sd(fmt(1)) count(fmt(0))")              ///
          booktabs label nogaps nostar unstack noobs nonote nomtitles nonumber    ///
          title ("") order(`order') `refcat'                             ///
          substitute({l} {p{\linewidth}})                             ///
          prehead(`"\begin{table}[htbp]\centering"'                     ///
                  `"\scriptsize"'                                        ///
                  `"\caption{Summary Statistics of Sample 1, in \%}"' ///
                  `"\label{tab:1}"'                ///
                  `"\begin{tabular}{l*{3}{|ccc}}"'                    ///
                  `"\toprule"'                                        ///
                  `" & \multicolumn{3}{c}{Category 1} & \multicolumn{3}{c}{Category 1} & \multicolumn{3}{c}{Total} \\"' ///
                  `"Indicator   &        Mean &          SD &  N & Mean &          SD &  N & Mean &          SD &  N\\"'    ///
                  )                                                    ///
                  addnote("\tiny `notes'")                               ///
          replace
      I'm still getting the -tabstat- headers after the \multicolumn, even using -nomtitles-. I color the redundant lines in red here:

      Code:
      \begin{table}[htbp]\centering
      \scriptsize
      \caption{Summary Statistics of Sample 1, in \%}
      \label{tab:1}
      \begin{tabular}{l*{3}{|ccc}}
      \toprule
       & \multicolumn{3}{c}{Category 1} & \multicolumn{3}{c}{Category 2} & \multicolumn{3}{c}{Total} \\
      Indicator   &        Mean &          SD &  N & Mean &          SD &  N & Mean &          SD &  N\\
                         &Attending school&            &            &Not attending school&            &            &       Total&            &            \\
                          &        mean&          sd&       count&        mean&          sd&       count&        mean&          sd&       count\\
      I didn't find where you place your \multicolumn command, but in any case, would you mind advising what to do, or where to look at?

      Thank you!
      Last edited by Emanuel Agu; 21 Aug 2023, 15:47.

      Comment

      Working...
      X